package com.pussinboots.morning.sync.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pussinboots.morning.sync.dao.ErpMorningOrderWritebackMapper;
import com.pussinboots.morning.sync.entity.ErpMorningOrderWriteback;
import com.pussinboots.morning.sync.service.IErpMorningOrderWritebackService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 订单状态回写 服务实现类
 * </p>
 *
 * @author TS
 * @since 2019-09-22
 */
@Service
@DS("erp")
public class ErpMorningOrderWritebackServiceImpl extends ServiceImpl<ErpMorningOrderWritebackMapper, ErpMorningOrderWriteback>
        implements IErpMorningOrderWritebackService {

    @Autowired
    private ErpMorningOrderWritebackMapper orderWritebackMapper;

    @Override
    public List<ErpMorningOrderWriteback> getOrderWriteBack() {
        val orderWritebackList = orderWritebackMapper.selectList(
                new QueryWrapper<ErpMorningOrderWriteback>()
                        .eq("IS_ZX", 0));
        if (orderWritebackList.isEmpty()) {
            return null;
        }
        return orderWritebackList;
    }

    @Override
    @Transactional
    public boolean execWriteBack(List<Long> orderNumbers) {
        try {
            orderWritebackMapper.execWriteBack(orderNumbers);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}